//
//  SetData.m
//  OST
//
//  Created by mac on 13-7-11.
//  Copyright (c) 2013年 mac. All rights reserved.
//

#import "GpsHistoryData.h"
#import "Common.h"

@interface GpsHistoryData ()

@end

@implementation GpsHistoryData
@synthesize ids;

- (void)requestFinished:(ASIHTTPRequest *)request
{
    NSArray *datas= [reciveData componentsSeparatedByString:@"\n" ];
    NSMutableArray *result = [NSMutableArray array];
    
    int length  = [datas count];
    for (int i=length-1; i>-1; i--) {
        NSString *item = [datas objectAtIndex:i];
        if ([item length]>0) {
            item = [item stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"pos_%@_",ids] withString:@""];
            if ([item length]>8) {
                
                NSString *label =[NSString stringWithFormat:@"20%@/%@/%@ %@:00",[item substringWithRange:NSMakeRange(0, 2)],[item substringWithRange:NSMakeRange(2, 2)],[item substringWithRange:NSMakeRange(4, 2)],[item substringWithRange:NSMakeRange(6, 2)]];
                
                NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                [dict setValue:[datas objectAtIndex:i] forKey:@"value"];
                [dict setValue:label forKey:@"name"];
                [result addObject:dict];
            }
        }
    }
    
    [self doneLoadData:result];
}


-(void)doneLoadData:(id)data
{
    [super doneLoadData:data];
}

-(void)reLoadData
{
    self.httpRequest = [Common createHTTPRequest:[NSString stringWithFormat:@"cgi-bin/getDBList.cgi?TN=pos_%@&R=1",ids] delegate:self];
    [self.httpRequest startAsynchronous];
}



@end
